<?php
/** @var $this SiteController */
/** @var $model Setting */
/** @var $form TbActiveForm */
$this->pageTitle = $model->getTitle();

$this->breadcrumbs = array(
	'设置' => array('site/setting', 'category' => 'general'),
	$this->pageTitle,
);
$tabs = array();
foreach ($categories as $id => $description) {
	$tabs[] = array('label' => $description, 'url' => array('setting', 'category' => $id), 'active' => $id == $category ? true : false);
}
?>
	<div class="page-header">
		<h1><?php echo CHtml::encode($this->pageTitle); ?></h1>

		<div class="btn-group pull-right">
			<?php echo CHtml::link('清空系统缓存', array('flushCache'), array('class' => 'btn btn-danger')); ?>
			<?php if ($this->menu): ?>
				<button data-toggle="dropdown" class="btn btn-primary dropdown-toggle"> 操作 <span class="caret"></span>
				</button>
				<?php $this->widget('bootstrap.widgets.TbDropdown', array(
					'items' => $this->menu,
				))?>
			<?php endif; ?>
		</div>
	</div>
<?php
$this->widget('bootstrap.widgets.TbTabs', array('tabs' => $tabs));
?>
<?php $form = $this->beginWidget('bootstrap.widgets.TbActiveForm', array(
	'id' => 'setting-form',
	'type' => 'horizontal',
	'enableClientValidation' => true,
	'clientOptions' => array(
		'validateOnSubmit' => true,
	),
)); ?>

	<p class="help-block"><span class="required">*</span> 字段必填.</p>

<?php echo $form->errorSummary($model); ?>

<?php foreach ($model->getOptions() as $name => $params):
	$type = isset($params['type']) ? $params['type'] : 'text';
	$hint = isset($params['hint']) ? $params['hint'] : null;
	$inputOptions = isset($params['inputOptions']) ? $params['inputOptions'] : array();
	if (!isset($inputOptions['class'])) {
		$inputOptions['class'] = 'span6';
	}
	switch ($type) {
		case 'html':
			/*
			$this->widget('ext.ckeditor.CkeditorWidget', array(
				'model' => $model,
				'form' => $form,
				'attribute' => $name,
				'options' => array('height' => 200),
				'htmlOptions' => array('hint' => $hint),
			));
			break;
			*/
		case 'textarea':
			echo $form->textAreaRow($model, $name, $inputOptions, array('hint' => $hint));
			break;
		case 'select':
			echo $form->dropDownListRow($model, $name, isset($params['data']) ? $params['data'] : array(), $inputOptions, array('hint' => $hint));
			break;
		case 'radio':
		case 'boolean':
		case 'bool':
			echo $form->radioButtonListRow($model, $name, isset($params['data']) ? $params['data'] : array(0 => '否', 1 => '是'), array('hint' => $hint));
			break;
		default:
			echo $form->textFieldRow($model, $name, $inputOptions, array('hint' => $hint));
	}
	?>
<?php endforeach; ?>

	<div class="form-actions">
		<?php $this->widget('bootstrap.widgets.TbButton', array(
			'buttonType' => 'submit',
			'type' => 'primary',
			'encodeLabel' => false,
			'label' => '<i class="fa fa-save"></i> 保存',
		)); ?>
	</div>

<?php $this->endWidget(); ?>